﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package zasp.Util {

    public class EMA implements Sampler {

        private var alpha_:Number = 0;
        private var value_:Number = 0;
        private var hasValue_:Boolean = false;

        public function EMA(_arg1:Number){
            if ((((_arg1 < 0)) || ((_arg1 > 1)))){
                throw (new Error((("alpha " + _arg1) + " not in [0..1]")));
            };
            this.alpha_ = _arg1;
            this.value_ = 0;
            this.hasValue_ = false;
        }
        public function sample(_arg1:Number):void{
            if (!this.hasValue){
                this.value_ = _arg1;
                this.hasValue_ = true;
            } else {
                this.value_ = ((this.alpha * _arg1) + ((1 - this.alpha) * this.value_));
            };
        }
        public function get hasValue():Boolean{
            return (this.hasValue_);
        }
        public function get value():Number{
            if (!this.hasValue_){
                return (0);
            };
            return (this.value_);
        }
        public function get alpha():Number{
            return (this.alpha_);
        }

    }
}//package zasp.Util 
